--[[

    Filename:	argchk.lua

    Programmer:	aesiot

    Remark:

--]]

local auxlib = require( "auxlib" )

local argchk = { _VERSION = "1.0" }

--------------------------------------------------------------------------------

function argchk.check_b( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_boolean( value ) or auxlib.is_none( value ), index, "(boolean expected)", level )
	else

		return auxlib.argcheck( auxlib.is_boolean( value ), index, "(boolean expected)", level )
	end
end

function argchk.check_i( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_integer( value ) or auxlib.is_none( value ), index, "(integer expected)", level )
	else

		return auxlib.argcheck( auxlib.is_integer( value ), index, "(integer expected)", level )
	end
end

function argchk.check_n( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_number( value ) or auxlib.is_none( value ), index, "(number expected)", level )
	else

		return auxlib.argcheck( auxlib.is_number( value ), index, "(number expected)", level )
	end
end

function argchk.check_s( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_string( value ) or auxlib.is_none( value ), index, "(string expected)", level )
	else

		return auxlib.argcheck( auxlib.is_string( value ), index, "(string expected)", level )
	end
end

function argchk.check_f( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_function( value ) or auxlib.is_none( value ), index, "(function expected)", level )
	else

		return auxlib.argcheck( auxlib.is_function( value ), index, "(function expected)", level )
	end
end

function argchk.check_u( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_userdata( value ) or auxlib.is_none( value ), index, "(userdata expected)", level )
	else

		return auxlib.argcheck( auxlib.is_userdata( value ), index, "(userdata expected)", level )
	end
end

function argchk.check_t( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_table( value ) or auxlib.is_none( value ), index, "(table expected)", level )
	else

		return auxlib.argcheck( auxlib.is_table( value ), index, "(table expected)", level )
	end
end

function argchk.check_c( value, index, optional, level )

	if optional then

		return auxlib.argcheck( auxlib.is_thread( value ) or auxlib.is_none( value ), index, "(thread expected)", level )
	else

		return auxlib.argcheck( auxlib.is_thread( value ), index, "(thread expected)", level )
	end
end

return argchk